<template>
  <div class="ocr-trip">
    <van-uploader  :max-count="1" :after-read="afterRead">
      <van-button icon="plus" type="primary" block>上传行程码</van-button>
    </van-uploader>
    <van-cell-group v-if="show">
      <van-cell title="行程卡更新时间"  :label="result.Time" />
      <van-cell title="行程卡颜色：绿色、黄色、红色"  :label="result.Color" />
      <van-cell title="14天内到达或途经的城市"  :label="item" v-for="(item,index) in result.ReachedCity" :key="index" />
      <van-cell title="14天内到达或途径存在中高风险地区的城市"  :label="item" v-for="(item,index) in result.RiskArea" :key="index" />
      <van-cell title="电话号码"  :label="result.Telephone" />
    </van-cell-group>
  </div>
</template>

<script>
import { travelCardOCR } from '../api/gov/home/index'
import { Toast } from 'vant'
export default {
  components: {},
  props: {},
  data () {
    return {
      // fileList: []
      result: {},
      show: false
    }
  },
  methods: {
    afterRead (file) {
      const T = Toast.loading({
        message: '正在识别...',
        forbidClick: true,
        loadingType: 'spinner',
        duration: 20000
      })
      // 此时可以自行将文件上传至服务器
      travelCardOCR({
        ImageBase64: file.content
      }).then(res => {
        console.log(res, '健康码返回')
        this.result = JSON.parse(res.data.data)
        this.show = true
        T.clear()
      })
    }
  }
}
</script>
<style lang="less" scoped>
.ocr-trip{
  width: 100%;
  .van-uploader{
    width: 100%;
  }
  /deep/.van-uploader__input-wrapper{
    width: 100%;
  }
}
</style>
